package com.ds.seqlist.LeetCode;

public class Num160_IntersectionNode {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        ListNode l1 = headA;
        ListNode l2 = headB;
        // 终止条件就是他俩汇合或者同时走到终点
        while (l1 != l2) {
            l1 = l1 == null ? headB : l1.next;
            l2 = l2 == null ? headA : l2.next;
//            if (l1 == null) {
//                l1 = headB;
//            }else {
//                l1 = l1.next;
//            }
//            if (l2 == null) {
//                l2 = headA;
//            }else {
//                l2 = l2.next;
//            }
        }
        return l1;
    }

}
